#include <bits/stdc++.h>
using namespace std;

struct carr{
	int d,v,a;
	bool cs = 0;
	int vmo;
	int dertax;
	int t;
}traf[3010];
int moni[3010];
bool monii[3010];

bool cmp(int a,int b)
{
	return a > b;
}

int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int T;
	cin >> T;
	bool flag = 0;
	int minn = 1 << 30;
	int maxx = 0;
	int w = 0;
	for(int i = 1; i <= T; i++)
	{	
		int num = 0;//monitor
		int csnum = 0;
		int numa1= 0;int numa2 = 0;int numa3 = 0;//>0 =0 <0
		int n,m,L,V;
		cin >> n >> m >> L >> V;
		for(int j = 1; j <= n; j++)
		{
			cin >> traf[j].d >> traf[j].v >> traf[j].a;
			if(traf[j].a > 0) numa1++;
			if(traf[j].a == 0) numa2++;
			if(traf[j].a < 0) numa3++;
		}
		for(int j = 1; j <= m; j++) cin >> moni[j];
		if(numa2 == n)//t3
		{
			for(int j = 1; j <= n; j++)
				if(traf[j].v > V) {traf[j].cs = 1;csnum++;}
			cout << csnum << " " << m-1;
			return 0;
		}
		if(numa1 == n)//t5
		{
			for(int j = 1; j <= n; j++)
			{
				if(traf[j].v >= V) csnum++;
				else{
					traf[j].t = (V-traf[j].v)/traf[j].a;
					traf[j].dertax = (V*V-traf[j].v*traf[j].v)/(2*traf[j].a) + traf[j].d;
					if(traf[j].dertax <= L)
					{
						csnum++;
					/*	for(int k = 1; k <= m; k++)
						{
							if(traf[j].dertax > moni[k] && monii[k] == 0)
							{
								num++; monii[k] = 1;
							}
						}
					}*/
					maxx = max(maxx,traf[j].dertax);
					minn = min(minn,traf[j].dertax);
					sort(moni,moni+m+1,cmp);
					for(int k = 1; k <= m; k++)
					{
						if(maxx >= moni[k]) flag = 1;
						if(minn <= moni[k]) w = 1;
					}
					if(flag){cout << csnum << " " << m-1;	return 0;}
					if(w == 1) {cout << csnum << " " << m; return 0;}
					}
				}	
			}
			cout << csnum << " " << num;
			return 0;			
		}
		if(numa3 == n)
		{
			for(int j = 1; j <= n; j++)
			{
				if(traf[j].v >= V) csnum++;
				traf[j].t = (V-traf[j].v)/traf[j].a;
				traf[j].dertax = (V*V-traf[j].v*traf[j].v)/(2*traf[j].a) + traf[j].d;
				if(traf[j].dertax <= L)
				{
					minn = min(minn,traf[j].dertax);
					maxx = max(maxx,traf[j].dertax);
					sort(moni,moni+m+1,cmp);
					for(int k = 1; k <= m; k++)
					{
						if(minn >= moni[k]) flag = 1;
						if(maxx <= moni[k]) w = 1;
					}
					if(flag){cout << csnum << " " << m-1;return 0;}
					if(w == 1) {cout << csnum << " " << m; return 0;}
				}
			}
		}
		num = 0;numa1 = 0;numa2 = 0;numa3 = 0;
		minn = 1 << 30;maxx = 0;flag = 0;w = 0;
	}	
	return 0;
}
